// pages/collect/index.js
var app = getApp()
var CommonUtils = app.CommonUtils
var Keys = require('../../assets/data/keys')
const Toptips = require('../../dist/toptips/index');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    datas: '',
    id: '',
    name: '',
    price: '',
    count: '',
    note: '',
    pj: '',
    star1: '',
    star2: '',
    star3: '',
    star4: '',
    star5: '',
    images: '',
    score: '',
    pj1: ''
  },

  /**
   * 跳转到商品详情页
   */
  jumpToGoodsDetail: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: "../goods-details/index?id=" + _this.data.datas[index].HJP_ID,
    })
  },

  /**
   * 删除商品
   */
  btnDel: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index
    wx.showModal({
      title: '提示',
      content: '确认从酒窖移除？',
      showCancel: true,
      cancelText: "否",
      confirmText: "是",
      success: function (res) {
        if (res.confirm) {
          wx.showToast({
            title: '请求网络删除',
          })
          _this.data.datas.splice(index, 1)
          _this.setData({
            datas: _this.data.datas
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this;
    wx.request({
      url: Keys.data.url_Order,
      data: {
        DataType: "Order_Product_Comment",
        hjcid: options.pj,
        uid: app.login_id
      },

      success: function (res) {
        console.log(res);
        if (res.data.isok == "false")
          _this.showZanTopTips(res.data.info);
        else {
          _this.setData({
            datas: res.data.datas,
            id: options.id,
            name: options.name,
            price: options.price,
            count: options.count,
            images: options.images,
            pj: options.pj,
            pj1: options.pj1

          })
          if (res.data.datas == null) {
            _this.setData({
              star1: '../../images/star_gray.png',
              star2: '../../images/star_gray.png',
              star3: '../../images/star_gray.png',
              star4: '../../images/star_gray.png',
              star5: '../../images/star_gray.png',
              score: '0'
            })
          } else {
            _this.setData({
              note: res.data.datas.HJC_Note,
              score: res.data.datas.HJC_Score
            })
            if (res.data.datas.HJC_Score == "1") {
              _this.setData({
                star1: '../../images/star_red.png',
                star2: '../../images/star_gray.png',
                star3: '../../images/star_gray.png',
                star4: '../../images/star_gray.png',
                star5: '../../images/star_gray.png',
              })
            } else if (res.data.datas.HJC_Score == "2") {
              _this.setData({
                star1: '../../images/star_red.png',
                star2: '../../images/star_red.png',
                star3: '../../images/star_gray.png',
                star4: '../../images/star_gray.png',
                star5: '../../images/star_gray.png',
              })
            } else if (res.data.datas.HJC_Score == "3") {
              _this.setData({
                star1: '../../images/star_red.png',
                star2: '../../images/star_red.png',
                star3: '../../images/star_red.png',
                star4: '../../images/star_gray.png',
                star5: '../../images/star_gray.png',
              })
            } else if (res.data.datas.HJC_Score == "4") {
              _this.setData({
                star1: '../../images/star_red.png',
                star2: '../../images/star_red.png',
                star3: '../../images/star_red.png',
                star4: '../../images/star_red.png',
                star5: '../../images/star_gray.png',
              })
            } else if (res.data.datas.HJC_Score == "5") {
              _this.setData({
                star1: '../../images/star_red.png',
                star2: '../../images/star_red.png',
                star3: '../../images/star_red.png',
                star4: '../../images/star_red.png',
                star5: '../../images/star_red.png',
              })
            }
          }
        }
      }
    })
  },

  btnClicked_comment: function () {
    wx.navigateTo({
      url: '../comment-detail/index',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


  tap1: function (e) {
    console.log(e.currentTarget.dataset.id);
    this.setData({
      score: '1',
      star1: '../../images/star_red.png',
      star2: '../../images/star_gray.png',
      star3: '../../images/star_gray.png',
      star4: '../../images/star_gray.png',
      star5: '../../images/star_gray.png',

    })
  },
  tap2: function (e) {
    console.log("tap2");
    this.setData({
      score: '2',
      star1: '../../images/star_red.png',
      star2: '../../images/star_red.png',
      star3: '../../images/star_gray.png',
      star4: '../../images/star_gray.png',
      star5: '../../images/star_gray.png',

    })
  },
  tap3: function (e) {
    console.log("tap3");
    this.setData({
      score: '3',
      star1: '../../images/star_red.png',
      star2: '../../images/star_red.png',
      star3: '../../images/star_red.png',
      star4: '../../images/star_gray.png',
      star5: '../../images/star_gray.png',

    })
  },
  tap4: function (e) {
    console.log("tap4");
    this.setData({
      score: '4',
      star1: '../../images/star_red.png',
      star2: '../../images/star_red.png',
      star3: '../../images/star_red.png',
      star4: '../../images/star_red.png',
      star5: '../../images/star_gray.png',

    })
  },
  tap5: function (e) {
    console.log("tap5");
    this.setData({
      score: '5',
      star1: '../../images/star_red.png',
      star2: '../../images/star_red.png',
      star3: '../../images/star_red.png',
      star4: '../../images/star_red.png',
      star5: '../../images/star_red.png',

    })
  },
  clickd_commit: function () {


    var _this = this;
    console.log(_this.data.pj1);
    console.log(_this.data.pj)
    console.log(app.login_id)
    console.log(_this.data.note)
    console.log(_this.data.score)
    if (_this.data.pj1 == 0) {
      wx.request({
        url: Keys.data.url_Order,
        data: {
          DataType: "Order_Product_Comment_Add",
          hosid: _this.data.pj,
          uid: app.login_id,
          note: _this.data.note,
          score: parseInt(_this.data.score)
        },
        success: function (res) {
          console.log(res);
          // wx.showModal({
          //   title: res.data.info,
          // })
          CommonUtils.showToastWithImg(res.data.info, 1)
        }
      })
    } else {
      wx.request({
        url: Keys.data.url_Order,
        data: {
          DataType: "Order_Product_Comment_Update",
          hjcid: _this.data.pj1,
          uid: app.login_id,
          note: _this.data.note,
          score: parseInt(_this.data.score)
        },
        success: function (res) {
          console.log(res);
          wx.showModal({
            title: res.data.info,
          })
        }
      })
    }
  },
  bindInput: function (e) {

    this.setData({
      note: e.detail.value
    })
  }
})
